package com.cai.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.cai.dao.MemberDao;
import com.cai.pojo.Member;
import com.cai.service.MemberService;
import com.cai.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;


@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;

    public Member findByTelephone(String telephone) {

        return memberDao.findByTelephone(telephone);
    }

    public void add(Member m) {
        if (m.getPassword()!=null){
            m.setPassword(MD5Utils.md5(m.getPassword()));
        }
            memberDao.add(m);
    }

    //根据月份获取会员数量
    public List<Integer> findMemberCountByMonth(List<String>month) {
        List<Integer>list=new ArrayList<>();
        for (String s : month) {
            s=s+".31";
            Integer count = memberDao.findMemberCountBeforeDate(s);
            list.add(count);
        }
        return list;
    }
}
